#pragma once
#include <QDebug>
#include <QDir>
#include <QFile>
#include <QFileInfo>
int spliterYUV(const QString& fileName, int w, int h, int frameCountPerFile = 120, int fileCount = 20)
{
	QFile inFile(fileName);
	if (!inFile.open(QFile::ReadOnly))
	{
		qWarning() << "open file error " << inFile.errorString();
		return -1;
	}
	int		   fileIndex = 0;
	int		   frameSize = w * h + w * h / 2;
	uint64_t   fileSize	 = frameCountPerFile * frameSize;
	const auto fileInfo	 = QFileInfo(fileName);

	const auto fileNameBase = fileInfo.absolutePath() + QDir::separator() + fileInfo.baseName();

	while (!inFile.atEnd())
	{
		QString outName = QString("%1_%2.yuv").arg(fileNameBase).arg(fileIndex);
		QFile	outFile(outName);
		if (!outFile.open(QFile::WriteOnly))
		{
			qWarning() << "open file error " << outFile.errorString();
			break;
		}
		auto data = inFile.read(fileSize);
		outFile.write(data);
		outFile.close();
		fileIndex++;
		if (fileIndex >= fileCount)
		{
			break;
		}
	}
	inFile.close();

	return 0;
}
